package com.sinopec.basemodule.utils;

import android.app.Activity;
import android.app.Dialog;
import android.view.Gravity;
import android.view.WindowManager;
import android.widget.TextView;

import com.sinopec.basemodule.R;


public class PopUtils {
    public static Dialog showExitPopWindow(final Activity activity, final PopClickListener listener) {
        return showPopWindow(activity, listener);
    }

    private static Dialog showPopWindow(final Activity activity, final PopClickListener listener) {

        Dialog dialog = new Dialog(activity, R.style.dialogStyle);
        dialog.setContentView(R.layout.popupwindow_camera_need);

        TextView bt_album = dialog.findViewById(R.id.btn_pop_album);
        TextView bt_cancel = dialog.findViewById(R.id.btn_pop_cancel);

        //获取屏幕宽高
        int weight = activity.getResources().getDisplayMetrics().widthPixels;
        int height = activity.getResources().getDisplayMetrics().heightPixels * 1 / 3;

        WindowManager.LayoutParams layoutParams = dialog.getWindow().getAttributes();
        layoutParams.width = weight;
        layoutParams.height = height;
        layoutParams.gravity = Gravity.BOTTOM;
        dialog.getWindow().setAttributes(layoutParams);

        bt_album.setOnClickListener(v -> {
            dialog.dismiss();
            listener.onItem2Click();

        });

        bt_cancel.setOnClickListener(v -> dialog.dismiss());

        dialog.show();

        return dialog;
    }

    public interface PopClickListener {
        void onItem1Click();

        void onItem2Click();
    }
}
